package com.ruoyi.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ErpAnnualTarget;
import com.ruoyi.erp.service.IErpAnnualTargetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年度目标Controller
 * 
 * @author yanwenliang
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/erp/target")
public class ErpAnnualTargetController extends BaseController
{
    @Autowired
    private IErpAnnualTargetService erpAnnualTargetService;

    /**
     * 查询年度目标列表
     */
    @PreAuthorize("@ss.hasPermi('erp:target:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpAnnualTarget erpAnnualTarget)
    {
        startPage();
        List<ErpAnnualTarget> list = erpAnnualTargetService.selectErpAnnualTargetList(erpAnnualTarget);
        return getDataTable(list);
    }

    /**
     * 导出年度目标列表
     */
    @PreAuthorize("@ss.hasPermi('erp:target:export')")
    @Log(title = "年度目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpAnnualTarget erpAnnualTarget)
    {
        List<ErpAnnualTarget> list = erpAnnualTargetService.selectErpAnnualTargetList(erpAnnualTarget);
        ExcelUtil<ErpAnnualTarget> util = new ExcelUtil<ErpAnnualTarget>(ErpAnnualTarget.class);
        util.exportExcel(response, list, "年度目标数据");
    }

    /**
     * 获取年度目标详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:target:query')")
    @GetMapping(value = "/{targetId}")
    public AjaxResult getInfo(@PathVariable("targetId") String targetId)
    {
        return success(erpAnnualTargetService.selectErpAnnualTargetByTargetId(targetId));
    }

    /**
     * 新增年度目标
     */
    @PreAuthorize("@ss.hasPermi('erp:target:add')")
    @Log(title = "年度目标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpAnnualTarget erpAnnualTarget)
    {
        return toAjax(erpAnnualTargetService.insertErpAnnualTarget(erpAnnualTarget));
    }

    /**
     * 修改年度目标
     */
    @PreAuthorize("@ss.hasPermi('erp:target:edit')")
    @Log(title = "年度目标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpAnnualTarget erpAnnualTarget)
    {
        return toAjax(erpAnnualTargetService.updateErpAnnualTarget(erpAnnualTarget));
    }

    /**
     * 删除年度目标
     */
    @PreAuthorize("@ss.hasPermi('erp:target:remove')")
    @Log(title = "年度目标", businessType = BusinessType.DELETE)
	@DeleteMapping("/{targetIds}")
    public AjaxResult remove(@PathVariable String[] targetIds)
    {
        return toAjax(erpAnnualTargetService.deleteErpAnnualTargetByTargetIds(targetIds));
    }
}
